<?php
define('USERNAME_REQUIRED', FALSE);
define('ACCOUNT_REQUIRED', FALSE);
include("global.php");

if(isset($_SESSION["username"])){
	header("Location: me.php");}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    
	<title><?php echo $sitename." - ".$lang['register']; ?></title>
    
	<?php echo $core->EscapeString($core->HeaderStyleJs()); ?>
    
    <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js"></script>
    
	<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.pack.js"></script>
    
</head> 

<body>

<?php if(isset($_GET["make"]) && $core->EscapeString($_GET["make"]) == "user"){ ?>

<div id="register_container">

	<div id="register_top">
    
    	<div id="register_title">
        
        	<?php echo $lang['register']; ?>
            
        </div>
        
        <div id="register_title_second">
        
        	<?php echo $lang['register_second']; ?>
            
        </div>
        
        <div id="register_middle">
        
        	<div id="register_middle_tekst">
            
        		<div id="left">
                
                	<?php if(isset($_GET["error"]) && $core->EscapeString($_GET["error"] == "username")){ ?><div id="errorbox"><div id="erroricon"></div><?php echo $lang['error_username']; ?></div><?php } ?>
                    
                    <?php if(isset($_GET["taken"]) && $core->EscapeString($_GET["taken"] == "username")){ ?><div id="errorbox"><div id="erroricon"></div><?php echo $lang['taken_username']; ?></div><?php } ?>
                    
                    <?php if(isset($_GET["signs"]) && $core->EscapeString($_GET["signs"] == "username")){ ?><div id="errorbox"><div id="erroricon"></div><?php echo $lang['signs_username']; ?></div><?php } ?>
                    
                    <?php if(isset($_GET["error"]) && $core->EscapeString($_GET["error"] == "password")){ ?><div id="errorbox"><div id="erroricon"></div><?php echo $lang['error_password']; ?></div><?php } ?>
                    
                    <?php if(isset($_GET["fould"]) && $core->EscapeString($_GET["fould"] == "password")){ ?><div id="errorbox"><div id="erroricon"></div><?php echo $lang['fould_password']; ?></div><?php } ?>
                    
                    <?php if(isset($_GET["error"]) && $core->EscapeString($_GET["error"] == "mail")){ ?><div id="errorbox"><div id="erroricon"></div><?php echo $lang['error_email']; ?></div><?php } ?>
                    
                    <?php if(isset($_GET["taken"]) && $core->EscapeString($_GET["taken"] == "mail")){ ?><div id="errorbox"><div id="erroricon"></div><?php echo $lang['taken_email']; ?></div><?php } ?>
                    
                    <?php if(isset($_GET["signs"]) && $core->EscapeString($_GET["signs"] == "mail")){ ?><div id="errorbox"><div id="erroricon"></div><?php echo $lang['signs_email']; ?></div><?php } ?>
                    
                    <?php if(isset($_GET["error"]) && $core->EscapeString($_GET["error"] == "date")){ ?><div id="errorbox"><div id="erroricon"></div><?php echo $lang['error_date']; ?></div><?php } ?>
                    
                	<form method="post" action="?add=user" name="frm">
                    
                	<div id="register_label"><?php echo $lang['username']; ?></div>
                    
                    <input type="text" name="username" <?php if(isset($_GET["error"]) && $core->EscapeString($_GET["error"] == "username")){ ?> style="border-color: red;color: red;"<?php } ?> <?php if(isset($_GET["taken"]) && $core->EscapeString($_GET["taken"] == "username")){ ?> style="border-color: red;color: red;"<?php } ?> <?php if(isset($_GET["signs"]) && $core->EscapeString($_GET["signs"] == "username")){ ?> style="border-color: red;color: red;"<?php } ?> placeholder="<?php echo $lang['username']; ?>" />
                    <div id="register_label_second"><?php echo $lang['username_message']; ?></div>
                    
                    <div id="space"></div>
                    
                    <div id="register_label"><?php echo $lang['password']; ?></div>
                    
                    <input type="password" name="password" <?php if(isset($_GET["error"]) && $core->EscapeString($_GET["error"] == "password")){ ?> style="border-color: red;color: red;"<?php } ?> <?php if(isset($_GET["fould"]) && $core->EscapeString($_GET["fould"] == "password")){ ?> style="border-color: red;color: red;"<?php } ?> placeholder="<?php echo $lang['password']; ?>" />
                    
                    <div id="register_label_second"><?php echo $lang['password_message']; ?></div>
                    
                    <div id="space"></div>
                    
                    <div id="register_label"><?php echo $lang['password_second']; ?></div>
                    
                    <input type="password" name="password_check" <?php if(isset($_GET["error"]) && $core->EscapeString($_GET["error"] == "password")){ ?> style="border-color: red;color: red;"<?php } ?> <?php if(isset($_GET["fould"]) && $core->EscapeString($_GET["fould"] == "password")){ ?> style="border-color: red;color: red;"<?php } ?> placeholder="<?php echo $lang['password']; ?>" />
                    
                    <div id="register_label_second"><?php echo $lang['password_message_second']; ?></div>
                    
                    <div id="space"></div>
                    
                    <div id="register_label"><?php echo $lang['email']; ?></div>
                    
                    <input type="text" name="mail" <?php if(isset($_GET["error"]) && $core->EscapeString($_GET["error"] == "mail")){ ?> style="border-color: red;color: red;"<?php } ?> <?php if(isset($_GET["taken"]) && $core->EscapeString($_GET["taken"] == "mail")){ ?> style="border-color: red;color: red;"<?php } ?> <?php if(isset($_GET["signs"]) && $core->EscapeString($_GET["signs"] == "mail")){ ?> style="border-color: red;color: red;"<?php } ?> placeholder="<?php echo $lang['email']; ?>" />
                    
                    <div id="register_label_second"><?php echo $lang['email_message']; ?></div>
                    
                    <div id="space"></div>
                    
                    <div id="register_label"><?php echo $lang['date']; ?></div>
                    
                    <div style="margin-left: -4px;">
                    
                    <select name="bdday" <?php if(isset($_GET["value"]) && $core->EscapeString($_GET["value"] == "1")){ ?> style="border-color: red;color: red;"<?php } ?> id="bdday">
                    
                		<option value=""><?php echo $lang['register_day']; ?></option>
                        
                    	<option value="1">1</option>
                        
                    	<option value="2">2</option>
                        
                  	  	<option value="3">3</option>
                        
                  	 	 <option value="4">4</option>
                         
                    	<option value="5">5</option>
                        
                    	<option value="6">6</option>
                        
                    	<option value="7">7</option>
                        
                    	<option value="8">8</option>
                        
                    	<option value="9">9</option>
                        
                    	<option value="10">10</option>
                        
                    	<option value="11">11</option>
                        
                    	<option value="12">12</option>
                        
                    	<option value="13">13</option>
                        
                    	<option value="14">14</option>
                        
                    	<option value="15">15</option>
                        
                    	<option value="16">16</option>
                        
                   		<option value="17">17</option>
                        
                   		<option value="18">18</option>
                        
                    	<option value="19">19</option>
                        
                    	<option value="20">20</option>
                        
                    	<option value="21">21</option>
                        
                    	<option value="22">22</option>
                        
                    	<option value="23">23</option>
                        
                    	<option value="24">24</option>
                        
                    	<option value="25">25</option>
                        
                    	<option value="26">26</option>
                        
                    	<option value="27">27</option>
                        
                    	<option value="28">28</option>
                        
                    	<option value="29">29</option>
                        
                    	<option value="30">30</option>
                        
                    	<option value="31">31</option>
                	</select> 
                    
                	<select name="bdmonth" <?php if(isset($_GET["value"]) && $core->EscapeString($_GET["value"] == "2")){ ?>style="border-color: red;color: red;"<?php } ?> id="bdmonth">
                    
                		<option value=""><?php echo $lang['register_month']; ?></option>
                        
                    	<option value="1"><?php echo $lang['january'] ?></option>
                        
	                    <option value="2"><?php echo $lang['february']; ?></option>
                        
    	                <option value="3"><?php echo $lang['march']; ?></option>
                        
        	            <option value="4"><?php echo $lang['april']; ?></option>
                        
            	        <option value="5"><?php echo $lang['may']; ?></option>
                        
                	    <option value="6"><?php echo $lang['june']; ?></option>
                        
                    	<option value="7"><?php echo $lang['july']; ?></option>
                        
	                    <option value="8"><?php echo $lang['august']; ?></option>
                        
    	                <option value="9"><?php echo $lang['september']; ?></option>
                        
        	            <option value="10"><?php echo $lang['october']; ?></option>
                        
            	        <option value="11"><?php echo $lang['november']; ?></option>
                        
                	    <option value="12"><?php echo $lang['december']; ?></option>
                        
                	</select> 
                    
                	<select name="bdyear" <?php if(isset($_GET["value"]) && $core->EscapeString($_GET["value"] == "3")){ ?>style="border-color: red;color: red;"<?php } ?> id="bdyear">
                    
	                	<option value=""><?php echo $lang['register_year']; ?></option>
                        
    	                <option value="2010">2010</option>
                        
        	            <option value="2009">2009</option>
                        
            	        <option value="2008">2008</option>
                        
                	    <option value="2007">2007</option>
                        
                    	<option value="2006">2006</option>
                        
	                    <option value="2005">2005</option>
                        
    	                <option value="2004">2004</option>
                        
        	            <option value="2003">2003</option>
                        
            	        <option value="2002">2002</option>
                        
                	    <option value="2001">2001</option>
                        
                    	<option value="2000">2000</option>
                        
	                    <option value="1999">1999</option>
                        
    	                <option value="1998">1998</option>
                        
        	            <option value="1997">1997</option>
                        
            	        <option value="1996">1996</option>
                        
                	    <option value="1995">1995</option>
                        
                    	<option value="1994">1994</option>
                        
	                    <option value="1993">1993</option>
                        
    	                <option value="1992">1992</option>
                        
        	            <option value="1991">1991</option>
                        
            	        <option value="1990">1990</option>
                        
                	    <option value="1989">1989</option>
                        
                    	<option value="1988">1988</option>
                        
	                    <option value="1987">1987</option>
                        
    	                <option value="1986">1986</option>
                        
        	            <option value="1985">1985</option>
                        
            	        <option value="1984">1984</option>
                        
                	    <option value="1983">1983</option>
                        
                    	<option value="1982">1982</option>
                        
	                    <option value="1981">1981</option>
                        
    	                <option value="1980">1980</option>
                        
        	            <option value="1979">1979</option>
                        
            	        <option value="1978">1978</option>
                        
                	    <option value="1977">1977</option>
                        
                    	<option value="1976">1976</option>
                        
	                    <option value="1975">1975</option>
                        
    	                <option value="1974">1974</option>
                        
        	            <option value="1973">1973</option>
                        
            	        <option value="1972">1972</option>
                        
                	    <option value="1971">1971</option>
                        
                    	<option value="1970">1970</option>
                        
               	 	</select>
                    
                    </div>
                    
                    <div id="register_label_second"><?php echo $lang['date_message']; ?></div>
                    
                    <div id="space"></div>
                    
					<script type="text/javascript">
					function apply()
						{
  							document.frm.sub.disabled=true;
  							if(document.frm.chk.checked==true)
  								{
    								document.frm.sub.disabled=false;
  								}
  							if(document.frm.chk.checked==false)
  								{
    								document.frm.sub.enabled=false;
  								}
						}
					</script>
                    
                    <input type="checkbox" style="margin-left: -90px;margin-right: -90px;" name="chk" onClick="apply()" name="terms" /> <?php echo $lang['terms']; ?>
                    
                    <div id="space"></div>
                    
                    <input type="submit" style="width: auto;" name="sub" disabled value="<?php echo $lang['register_button']; ?>" />
                    
                    </form>
                    
                    <a href="index.php">
                    
                    	<input type="submit" style="float: right; margin-top: -65px;" value="<?php echo $lang['cancle_button']; ?>" />
                        
                    </a>

                </div>
                
                <div id="right">
                
            		<div id="titel_box"><?php echo $lang['avatar_on_the_moment']; ?></div>
                    
                    <center>
                    
                    	<img style="margin-left: -20px;" align="center" src="http://www.habbo.com/habbo-imaging/avatarimage?figure=<?php echo $registerlook; ?>&direction=3&head_direction=3&gesture=sml&action=wav" />
                        
                    </center>
            </div>
            
            </div>
            
        </div>
        
        </div>
        
    <div id="register_bottom"></div>
    
    <center><?php include("system/footer.php"); ?></center>
    
</div>

<?php  
}if(isset($_GET["add"]) && $_GET["add"] == "user"){ 

if($core->EscapeString($_POST['password']) < $core->EscapeString($_POST['password_check']) || $core->EscapeString($_POST['password']) > $core->EscapeString($_POST['password_check'])){ header("Location: ?make=user&fould=password"); 

}elseif($core->EscapeString($_POST['username']) == NULL){ header("Location: ?make=user&error=username");

}elseif($core->EscapeString($_POST['password']) == NULL){ header("Location: ?make=user&error=password");

}elseif($core->EscapeString($_POST['mail']) == NULL){ header("Location: ?make=user&error=mail");

}elseif($core->EscapeString($_POST['bdday']) == NULL){ header("Location: ?make=user&error=date&value=1");

}elseif($core->EscapeString($_POST['bdmonth']) == NULL){ header("Location: ?make=user&error=date&value=2");

}elseif($core->EscapeString($_POST['bdyear']) == NULL){ header("Location: ?make=user&error=date&value=2");

}elseif(preg_match('/^[a-zA-Z0-9-=?!@:.]+$/i', $core->EscapeString($_POST['username'])) == 0){
	header("Location: ?make=user&signs=username");
	
}elseif(preg_match('/^[a-zA-Z0-9@.]+$/i', $core->EscapeString($_POST['mail'])) == 0){
	header("Location: ?make=user&signs=mail");
	
}elseif($core->EscapeString($_POST['username']) || $core->EscapeString($_POST['mail'])){ 

$userchecker = mysql_query("SELECT username FROM users WHERE username = '".$core->EscapeString($_POST['username'])."'");

$usercounter = mysql_num_rows($userchecker);

$mailchecker = mysql_query("SELECT mail FROM users WHERE mail = '".$core->EscapeString($_POST['mail'])."'");

$mailcounter = mysql_num_rows($mailchecker);

if($usercounter > 0){ header("Location: register.php?make=user&taken=username");

}elseif($mailcounter > 0){ header("Location: register.php?make=user&taken=mail");

}else{ $query = mysql_query("INSERT INTO users (username, password, mail, credits, activity_points, look, motto, account_created, last_online, ip_last, ip_reg, home_room, belcredits, profiel_stijl, profiel_achtergrond, date) VALUES ('".$core->EscapeString($_POST['username'])."', '".$core->EscapeString(md5($_POST['password']))."', '".$core->EscapeString($_POST['mail'])."', '".$registercredits."', '".$registerpixels."', '".$registerlook."', '".$registermotto."', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), '".$_SERVER['REMOTE_ADDR']."', '".$_SERVER['REMOTE_ADDR']."', '".$registerhomeroom."', '".$registerbelcredits."', 'home', 'bg_wood2.png', '".$core->EscapeString($_POST['bdyear'])."-".$core->EscapeString($_POST['bdmonth'])."-".$core->EscapeString($_POST['bdday'])."');");

}

}
?>
<div id="register_container">

	<div id="register_top">
    
    	<div id="register_title">
        
        	<?php echo $lang['almost_done']; ?>
            
        </div>
        
        <div id="register_title_second">
        
        	<?php echo $lang['only_sign_in']; ?>
            
        </div>
        
        <div id="register_middle">
        
        	<div id="register_middle_tekst">
            
            	<form method="post" action="system/first_login.php">
                
                	<input type="hidden" name="username" value="<?php echo $core->EscapeString($_POST['username']); ?>" />
                    
                    <input type="hidden" name="password" value="<?php echo $core->EscapeString($_POST['password']); ?>" />
                    
					<input type="submit" value="<?php echo $lang['click_to_sign_in']; ?>" />
                    
                    <div style="margin-top: -20px;"></div>
                    
                </form>
                
            </div>
            
        </div>
        
        </div>
        
    <div id="register_bottom"></div>
    
    <center>
	
		<?php include("system/footer.php"); ?>
    
    </center>
    
</div>

<?php } ?>

</body>
</html>